package org.cristiangm.dados;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;

public class Dados extends Activity implements OnClickListener, OnItemSelectedListener{
    /** Called when the activity is first created. */
    
	private String stringNumDados ="1";
	private String stringTiradas = "1";

	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Spinner numeroDados = (Spinner) this.findViewById(R.id.numDados);
        ArrayAdapter<String> dados = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.arrayNumDados));
        dados.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        numeroDados.setAdapter(dados);
        
        Spinner numeroTiradas = (Spinner) this.findViewById(R.id.tiradasSpinner);
        ArrayAdapter<String> tiradas = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.arrayTiradas));
        tiradas.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        numeroTiradas.setAdapter(tiradas);
        
        numeroDados.setOnItemSelectedListener(this);
        numeroTiradas.setOnItemSelectedListener(this); 
        
        Button botonTirar = (Button)findViewById(R.id.boton_Tirar);
        botonTirar.setOnClickListener(this);
        
    }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.boton_Tirar:
			Intent i = new Intent (this, resultados.class);
			i.putExtra("com.cristiangm.dados.Dados.stringNumDados", stringNumDados);
			i.putExtra("com.cristiangm.dados.Dados.stringTiradas", stringTiradas);
			startActivity(i);
			break;
		default:
			break;
		}
		
	}
	
	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (arg0.getId()){	
			case R.id.numDados:
				stringNumDados = arg0.getItemAtPosition(arg2).toString();
				break;
			case R.id.tiradasSpinner:
				stringTiradas = arg0.getItemAtPosition(arg2).toString();
				break;
			default:
				break;
		}
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}

}
